﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using S4Store.Service;
using S4Store.Domain.Report;
using S4Store.Models.Starnd;
using S4Store.Domain.ExhibitionKpi;
using S4Store.Domain.TelSaleKpi;
using S4Store.Domain.NetMarketingKpi;

namespace S4Store.Controllers
{
    public class StarndController : ReportBaseController
    {

        public ReportService ReportService { get; set; }
        public ExhibitionKpiService ExhibitionKpiService { get; set; }
        public TelSaleKpiService TelSaleKpiService { get; set; }
        public NetMarketingKpiService NetMarketingKpiService { get; set; }

        public ActionResult SellerStarnd()
        {
            SellerStarndModel model = new SellerStarndModel();
            this.InjectReportModel(model);
            model.BarModel.AddView( Models.ReportBarModel.ViewItem.Month);
            model.BarModel.Action = "SellerStarnd";
            model.BarModel.Controller = "Starnd";
            if (CurrentUser.Position != Domain.Position.SystemManager)
            {
                model.BarModel.RemoveView(Models.ReportBarModel.ViewItem.Stores);
            }
            using (var t = new Transtion())
            {
                t.Inject(ReportService);
                model.SellerPerformanceStandard = ReportService.GetSellerPerformanceStandard(Month.Year, Month.Month,Store.Id);
                t.Commit();
                return View(model);
            }
            
        }

        public JsonResult SaveSellerPerformanceStandard(SellerPerformanceStandard model)
        {
            using (var t = new Transtion())
            {
                t.Inject(ReportService);
                var standard = ReportService.SaveSellerPerformanceStandard(model);
                t.Commit();
                return new JsonResult
                {
                    Data = new
                    {
                        success = true
                    }
                };
            }
        }

        public ActionResult ExhibitionKpiStandard()
        {
            ExhibitionKpiStandardModel model = new ExhibitionKpiStandardModel();
            this.InjectReportModel(model);
            model.BarModel.AddView(Models.ReportBarModel.ViewItem.Month);
            model.BarModel.Action = "ExhibitionKpiStandard";
            model.BarModel.Controller = "Starnd";
            if (CurrentUser.Position != Domain.Position.SystemManager)
            {
                model.BarModel.RemoveView(Models.ReportBarModel.ViewItem.Stores);
            }
            using (var t = new Transtion())
            {
                t.Inject(ExhibitionKpiService);
                model.ExhibitionKpiStandard = ExhibitionKpiService.GetExhibitionKpiStandard(Month.Year, Month.Month, Store.Id);
                t.Commit();
                return View(model);
            }

        }

        public JsonResult SaveExhibitionKpiStandard(ExhibitionKpiStandard model)
        {
            using (var t = new Transtion())
            {
                t.Inject(ExhibitionKpiService);
                var standard = ExhibitionKpiService.SaveExhibitionKpiStandard(model);
                t.Commit();
                return new JsonResult
                {
                    Data = new
                    {
                        success = true
                    }
                };
            }
        }


        public ActionResult TelSaleKpiStandard()
        {
            TelSaleKpiStandardModel model = new TelSaleKpiStandardModel();
            this.InjectReportModel(model);
            model.BarModel.AddView(Models.ReportBarModel.ViewItem.Month);
            model.BarModel.Action = "TelSaleKpiStandard";
            model.BarModel.Controller = "Starnd";
            if (CurrentUser.Position != Domain.Position.SystemManager)
            {
                model.BarModel.RemoveView(Models.ReportBarModel.ViewItem.Stores);
            }
            using (var t = new Transtion())
            {
                t.Inject(TelSaleKpiService);
                model.TelSaleKpiStandard = TelSaleKpiService.GetTelSaleKpiStandard(Month.Year, Month.Month, Store.Id);
                t.Commit();
                return View(model);
            }

        }

        public JsonResult SaveTelSaleKpiStandard(TelSaleKpiStandard model)
        {
            using (var t = new Transtion())
            {
                t.Inject(TelSaleKpiService);
                var standard = TelSaleKpiService.SaveTelSaleKpiStandard(model);
                t.Commit();
                return new JsonResult
                {
                    Data = new
                    {
                        success = true
                    }
                };
            }
        }


        public ActionResult NetMarketingStandard()
        {
            NetMarketingStandardModel model = new NetMarketingStandardModel();
            this.InjectReportModel(model);
            model.BarModel.AddView(Models.ReportBarModel.ViewItem.Month);
            model.BarModel.Action = "NetMarketingStandard";
            model.BarModel.Controller = "Starnd";
            if (CurrentUser.Position != Domain.Position.SystemManager)
            {
                model.BarModel.RemoveView(Models.ReportBarModel.ViewItem.Stores);
            }
            using (var t = new Transtion())
            {
                t.Inject(NetMarketingKpiService);
                model.NetMarketingStandard = NetMarketingKpiService.GetNetMarketingStandard(Month.Year, Month.Month, Store.Id);
                t.Commit();
                return View(model);
            }

        }

        public JsonResult SaveNetMarketingStandard(NetMarketingStandard model)
        {
            using (var t = new Transtion())
            {
                t.Inject(NetMarketingKpiService);
                var standard = NetMarketingKpiService.SaveNetMarketingStandard(model);
                t.Commit();
                return new JsonResult
                {
                    Data = new
                    {
                        success = true
                    }
                };
            }
        }
    }
}
